package team.zero.lemon.module.sys.news.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.security.session.SessionContext;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.sys.news.entity.News;
import team.zero.lemon.module.sys.news.service.NewsService;

/**
 * Created by bolin on 2016/11/14.
 */
@Controller
@ResponseBody
@AuthPassport
@RequestMapping(value = "${adminPath}/sys/news", method = {RequestMethod.POST, RequestMethod.GET})
public class NewsController extends BaseController {
    @Autowired
    private NewsService newsService;

    @AuthPassport
    @RequestMapping("/query/page")
    public Page<News> findNews(@RequestBody News news) {
        if (news.getUserId() == null) {
            news.setUserId(SessionContext.getSession().getId());
        }
        return newsService.findPage(news);
    }

    @AuthPassport
    @RequestMapping("/read")
    public boolean read(@RequestBody News news) {
        return newsService.read(news);
    }
}
